package agenda;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;

/*
 * JanelaEvento.java
 *
 * Created on 11/11/2011, 19:57:47
 */

/**
 *
 * @author Brenno
 */
public class JanelaEvento extends javax.swing.JFrame {

    /** Creates new form JanelaEvento */
    public JanelaEvento(Evento Evento) {
    	this.Evento = Evento;
        indice = Agenda.Eventos.indexOf(Evento);
    	initComponents();
        setDefaultCloseOperation(HIDE_ON_CLOSE);
        setIconImage((new ImageIcon(getClass().getResource("/agenda/logo.png")).getImage()));
        setTitle("Dados do evento");
        this.setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
    	
        jPanel1 = new javax.swing.JPanel();
        
        jLabelCadastrarEventos = new javax.swing.JLabel();
        jLabelNome = new javax.swing.JLabel();
        jLabelData = new javax.swing.JLabel();
        jLabelHorário = new javax.swing.JLabel();
        jLabelDuracao = new javax.swing.JLabel();
        jLabelContato = new javax.swing.JLabel();
        jLabelTipo = new javax.swing.JLabel();
        jTextFieldNome = new javax.swing.JTextField(Evento.getNome());
        jTextFieldTipo = new javax.swing.JTextField(Evento.getTipo());
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaDescricao = new javax.swing.JTextArea(Evento.getDescricao());
        jButtonaddTexto = new javax.swing.JButton();
        jButtonAddaudio = new javax.swing.JButton();
        jButtonSalvar = new javax.swing.JButton();
        jButtonCancelar = new javax.swing.JButton();
        jFormattedTextFieldHorario = new javax.swing.JFormattedTextField(Evento.getHorario());
        jFormattedTextFieldDuracao = new javax.swing.JFormattedTextField(Evento.getDuracao());
        jFormattedTextFieldData = new javax.swing.JFormattedTextField(Evento.getData());
        jButtonAddFoto = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        Contatos = new javax.swing.JTable();
        jLabelDescricao1 = new javax.swing.JLabel();
        jButtonAddContato = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        ContatosRelacionados = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        Anotações = new javax.swing.JTable();
        jButtonRemoverContato = new javax.swing.JButton();
        jButtonVeranotação = new javax.swing.JButton();
        jLabelContatoRelacioandos = new javax.swing.JLabel();
        jButtonRemoverAnotação = new javax.swing.JButton();
        jLabelAnotações = new javax.swing.JLabel();
        jButtonExcluir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabelCadastrarEventos.setFont(new java.awt.Font("Monotype Corsiva", 3, 36)); // NOI18N
        jLabelCadastrarEventos.setText("Dados do Evento");

        jLabelNome.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabelNome.setText("Nome:");

        jLabelData.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabelData.setText("Data:");

        jLabelHorário.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabelHorário.setText("Horário:");

        jLabelDuracao.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabelDuracao.setText("Duração:");

        jLabelContato.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabelContato.setText("Contatos");

        jLabelTipo.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabelTipo.setText("Tipo:");

        jTextAreaDescricao.setColumns(20);
        jTextAreaDescricao.setRows(5);
        jScrollPane1.setViewportView(jTextAreaDescricao);
        
        jButtonExcluir.setIcon(new ImageIcon(getClass().getResource("/agenda/remove-event-icon.png")));
        jButtonExcluir.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				Agenda.Eventos.remove(indice);
				setVisible(false);
				dispose();
			}
        	
        });
        
        jButtonaddTexto.setIcon(new ImageIcon(getClass().getResource("/agenda/Texto.png"))); // NOI18N
        jButtonaddTexto.addActionListener(new ActionListener(){
        	public void actionPerformed(ActionEvent e) {
				final JFrame Arquivo = new JFrame("Anotação de ");
				Arquivo.setIconImage((new ImageIcon(getClass().getResource("/agenda/logo.png")).getImage()));
			    Arquivo.setLocationRelativeTo(null);  
				Arquivo.setSize(310,240);
				JPanel Painel = new JPanel();
				JLabel Nome = new JLabel("Nome");
				final JTextField nome = new JTextField(20);
				JLabel Data = new JLabel("Data");
				final JTextField data = new JTextField(20);
				JLabel Anotacao = new JLabel("Anotação");
				final JTextArea anotacao = new JTextArea();
				anotacao.setColumns(20);
		        anotacao.setRows(5);
				JButton Ok = new JButton("Ok");
				
				Ok.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent arg0) {
						Evento.addAnotacoes(new Anotação(nome.getText(),data.getText(),anotacao.getText()));
						Arquivo.setVisible(false);
						Arquivo.dispose();
						CarregaAnotações();
					}
					
				});
				Painel.add(Nome);Painel.add(nome);Painel.add(Data);Painel.add(data);Painel.add(Anotacao);Painel.add(anotacao);Painel.add(Ok);
				Arquivo.add(Painel);Arquivo.setVisible(true);
			}
        });
        jButtonAddaudio.setIcon(new ImageIcon(getClass().getResource("/agenda/Audio.png"))); // NOI18N
        jButtonAddaudio.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg0) {
				final JFrame Arquivo = new JFrame("Audio");
				Arquivo.setIconImage((new ImageIcon(getClass().getResource("/agenda/logo.png")).getImage()));
			    Arquivo.setLocationRelativeTo(null);  
				Arquivo.setSize(150,190);
				JPanel Painel = new JPanel();
				JLabel Nome = new JLabel("Nome");
				final JTextField nome = new JTextField(10);
				JLabel Data = new JLabel("Data");
				final JTextField data = new JTextField(10);
				JButton arquivo = new JButton("Arquivo");
				arquivo.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent arg0) {
						JFileChooser fc = new JFileChooser();
						fc.setFileFilter(new FileNameExtensionFilter("MP3","mp3"));
						fc.showOpenDialog(null);
						try {
							Evento.addAnotacoes(new Anotação(nome.getText(),data.getText(),fc.getSelectedFile()));
						} catch (IOException e) {
							e.printStackTrace();
						}
						Arquivo.setVisible(false);
						Arquivo.dispose();
						CarregaAnotações();
					}
					
				});
				Painel.add(Nome);Painel.add(nome);Painel.add(Data);Painel.add(data);Painel.add(arquivo);
				Arquivo.add(Painel);Arquivo.setVisible(true);			
			}
        	
        });
        
        jButtonSalvar.setIcon(new ImageIcon(getClass().getResource("/agenda/ip_icon_02_Ok.png"))); // NOI18N
        jButtonSalvar.setText("Salvar");
        jButtonSalvar.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Evento.setNome(jTextFieldNome.getText());
				Evento.setData(jFormattedTextFieldData.getText()) ;
				Evento.setDuracao(jFormattedTextFieldDuracao.getText());
				Evento.setHorario(jFormattedTextFieldHorario.getText());
				Evento.setDescricao(jTextAreaDescricao.getText());
				Evento.setTipo(jTextFieldTipo.getText());
				try {
					Agenda.Eventos.remove(indice);
					//Agenda.Eventos.set(indice,Evento);
					if (Agenda.ChecaChoquedeEventos(Evento)) {
						Agenda.Eventos.add(indice,Evento);
					}
					else{
						final JFrame Choque = new JFrame("Choque de horário entre eventos"); 
						Choque.setSize(400, 150);
					    Choque.setLocationRelativeTo(null);  
						Choque.setDefaultCloseOperation(HIDE_ON_CLOSE);
				        Choque.setIconImage((new ImageIcon(getClass().getResource("/agenda/logo.png")).getImage()));
						JPanel JPanel = new JPanel();
						JLabel icone = new JLabel(new ImageIcon(getClass().getResource("/agenda/error.png")));
						JLabel Mensagem1 = new JLabel("Esse evento possui choque de horário com outro já existente");
						JLabel Mensagem2 = new JLabel("Deseja cadastrar o evento mesmo assim ?");
						JButton sim = new JButton("Sim");
						sim.addActionListener(new ActionListener(){
							public void actionPerformed(ActionEvent arg0) {
								Agenda.Eventos.add(indice,Evento);
								Choque.setVisible(false);
								Choque.dispose();
								new JanelaEventos().setVisible(true);
							}
							
						});
						JButton nao = new JButton("Não");
						nao.addActionListener(new ActionListener(){
							public void actionPerformed(ActionEvent e) {
								Choque.setVisible(false);
								Choque.dispose();
								new JanelaEventos().setVisible(true);
							}
						});
						
						JPanel.add(icone);JPanel.add(Mensagem1);JPanel.add(Mensagem2);JPanel.add(sim);JPanel.add(nao);
						Choque.add(JPanel);
						Choque.setVisible(true);
					}
				} catch (Exception e) {
					JFrame Erro = new JFrame("Erro"); 
					Erro.setSize(310, 150);
					Erro.setDefaultCloseOperation(HIDE_ON_CLOSE);
			        Erro.setIconImage((new ImageIcon(getClass().getResource("/agenda/logo.png")).getImage()));
					JPanel JPanel = new JPanel();
					JLabel icone = new JLabel(new ImageIcon(getClass().getResource("/agenda/error.png")));
					JLabel Mensagem1 = new JLabel("Erro!");
					JLabel Mensagem2 = new JLabel("O Formato da hora e da duração deve ser hh:mm");
					JLabel Mensagem3 = new JLabel("O formato da data deve ser no formato dd/mm/aa");
					JPanel.add(icone);JPanel.add(Mensagem1);JPanel.add(Mensagem2);JPanel.add(Mensagem3);
					Erro.add(JPanel);
					Erro.setVisible(true);
				}
				try {
					Arquivos.salvarObjeto(new File("eventos.dat"), Agenda.Eventos);
				} catch (Exception e) {
					e.printStackTrace();
				}
				setVisible(false);
    			dispose();
			}
        });
        jButtonCancelar.setIcon(new ImageIcon(getClass().getResource("/agenda/ip_icon_02_Cancel.png"))); // NOI18N
        jButtonCancelar.setText("Cancelar");
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener(){
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				dispose();
			}
        	
        });

        jButtonAddFoto.setIcon(new ImageIcon(getClass().getResource("/agenda/Foto.png"))); // NOI18N
        jButtonAddFoto.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				final JFrame Arquivo = new JFrame("Anotação de Foto");
				Arquivo.setIconImage((new ImageIcon(getClass().getResource("/agenda/logo.png")).getImage()));
			    Arquivo.setLocationRelativeTo(null);  
				Arquivo.setSize(150,190);
				JPanel Painel = new JPanel();
				JLabel Nome = new JLabel("Nome");
				final JTextField nome = new JTextField(10);
				JLabel Data = new JLabel("Data");
				final JTextField data = new JTextField(10);
				JButton arquivo = new JButton("Arquivo");
				arquivo.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent arg0) {
						JFileChooser fc = new JFileChooser();
						fc.setFileFilter(new FileNameExtensionFilter("JPG","jpg"));
						fc.showOpenDialog(null);
						try {
							Evento.addAnotacoes(new Anotação(nome.getText(),data.getText(),fc.getSelectedFile()));
						} catch (IOException e) {
							e.printStackTrace();
						}
						Arquivo.setVisible(false);
						Arquivo.dispose();
						CarregaAnotações();
					}
					
				});
				Painel.add(Nome);Painel.add(nome);Painel.add(Data);Painel.add(data);Painel.add(arquivo);
				Arquivo.add(Painel);Arquivo.setVisible(true);
			}
        });

        Contatos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "Endereco", "Celular"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        DefaultTableModel modelo = (DefaultTableModel) Contatos.getModel();
		for(int i=0;i<Agenda.Contatos.size();i++){
			modelo.addRow(new String[]{Agenda.Contatos.get(i).getNome(),Agenda.Contatos.get(i).getEndereco(),Agenda.Contatos.get(i).getDataDeAniversario()});
		}
        jScrollPane2.setViewportView(Contatos);

        jLabelDescricao1.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabelDescricao1.setText("Descrição:");

        jButtonAddContato.setText("Adicionar Contato ao evento");
        jButtonAddContato.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				try{
					Evento.CadastraContatos(Agenda.Contatos.get(Contatos.getSelectedRow()));
					 CarregaContatosRelacionados();
				}
				catch(Exception E){
					final JFrame Erro = new JFrame();
					Erro.setIconImage((new ImageIcon(getClass().getResource("/agenda/logo.png")).getImage()));
				    Erro.setLocationRelativeTo(null);  
					Erro.setSize(200,100);
					JPanel Painel = new JPanel();
					JLabel Mensagem = new JLabel("Selecione algum item primeiro");
					JButton Ok = new JButton("Ok");
					Ok.addActionListener(new ActionListener(){
						@Override
						public void actionPerformed(ActionEvent arg0) {
							Erro.setVisible(false);
							Erro.dispose();
						}
						
					});
					Painel.add(Mensagem);Painel.add(Ok);Erro.add(Painel);
					Erro.setVisible(true);
				}
			}
        });

        CarregaContatosRelacionados();
        
        jScrollPane3.setViewportView(ContatosRelacionados);

        CarregaAnotações();
        jScrollPane4.setViewportView(Anotações);

        jButtonRemoverContato.setText("Remover Contato");
        jButtonRemoverContato.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent arg0) {
				Evento.getContatos().remove(ContatosRelacionados.getSelectedRow());
				CarregaContatosRelacionados();
			}
        	
        });

        jButtonVeranotação.setText("Ver anotação");
        jButtonVeranotação.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Anotação Anotacao = Evento.getAnotacoes().get(Anotações.getSelectedRow());
				try{
					if(Anotacao.getFile().getName().substring(Anotacao.getFile().getName().lastIndexOf(".")+1).equals("jpg")||Anotacao.getFile().getName().substring(Anotacao.getFile().getName().lastIndexOf(".")+1).equals("JPG")){
						new JanelaFoto(Anotacao).setVisible(true);
					}
					if(Anotacao.getFile().getName().substring(Anotacao.getFile().getName().lastIndexOf(".")+1).equals("mp3")){
						new Player(Anotacao).setVisible(true);
					}
				}catch(Exception e){
					new JanelaTexto(Anotacao).setVisible(true);
				}
				
			}
        	
        });
        
        jLabelContatoRelacioandos.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabelContatoRelacioandos.setText("Contatos Relacionados");
        jButtonRemoverAnotação.setText("Remover anotação");
        jButtonRemoverAnotação.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Evento.getAnotacoes().remove(Anotações.getSelectedRow());
				CarregaAnotações();
			}
        	
        });

        jLabelAnotações.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        jLabelAnotações.setText("Anotações");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(154, 154, 154)
                        .addComponent(jLabelContato))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jButtonAddContato)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addContainerGap()
                                    .addComponent(jLabelAnotações)
                                    .addGap(57, 57, 57)
                                    .addComponent(jButtonRemoverContato))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                    .addContainerGap()
                                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(102, 102, 102)
                                .addComponent(jLabelContatoRelacioandos)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jButtonAddFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonAddaudio, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jButtonaddTexto, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 582, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jButtonRemoverAnotação)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButtonVeranotação))
                                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jButtonCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jButtonSalvar, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabelTipo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabelData)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jFormattedTextFieldData, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabelHorário)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jFormattedTextFieldHorario, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabelDuracao)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jFormattedTextFieldDuracao, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabelDescricao1, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabelNome)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldNome, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)))
                        .addGap(114, 114, 114))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(184, 184, 184)
                        .addComponent(jLabelCadastrarEventos, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelCadastrarEventos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelNome)
                    .addComponent(jTextFieldNome, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelTipo)
                    .addComponent(jTextFieldTipo, javax.swing.GroupLayout.DEFAULT_SIZE, 22, Short.MAX_VALUE)
                    .addComponent(jLabelData)
                    .addComponent(jFormattedTextFieldData, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE)
                    .addComponent(jLabelHorário)
                    .addComponent(jFormattedTextFieldHorario, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                    .addComponent(jLabelDuracao)
                    .addComponent(jFormattedTextFieldDuracao, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabelDescricao1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelContato)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonAddContato)
                        .addGap(5, 5, 5)
                        .addComponent(jLabelContatoRelacioandos)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButtonRemoverContato)
                            .addComponent(jLabelAnotações)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonAddFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonAddaudio, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonaddTexto, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonVeranotação)
                            .addComponent(jButtonRemoverAnotação)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButtonSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(34, 34, 34))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 661, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>




    // Variables declaration - do not modify
    private static javax.swing.JTable Anotações;
    private javax.swing.JTable Contatos;
    private static javax.swing.JTable ContatosRelacionados;
    private javax.swing.JButton jButtonAddContato;
    private javax.swing.JButton jButtonAddFoto;
    private javax.swing.JButton jButtonAddaudio;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonRemoverAnotação;
    private javax.swing.JButton jButtonRemoverContato;
    private javax.swing.JButton jButtonSalvar;
    private javax.swing.JButton jButtonVeranotação;
    private javax.swing.JButton jButtonaddTexto;
    private javax.swing.JFormattedTextField jFormattedTextFieldData;
    private javax.swing.JFormattedTextField jFormattedTextFieldDuracao;
    private javax.swing.JFormattedTextField jFormattedTextFieldHorario;
    private javax.swing.JLabel jLabelAnotações;
    private javax.swing.JLabel jLabelCadastrarEventos;
    private javax.swing.JLabel jLabelContato;
    private javax.swing.JLabel jLabelContatoRelacioandos;
    private javax.swing.JLabel jLabelData;
    private javax.swing.JLabel jLabelDescricao1;
    private javax.swing.JLabel jLabelDuracao;
    private javax.swing.JLabel jLabelHorário;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JLabel jLabelTipo;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextArea jTextAreaDescricao;
    private javax.swing.JTextField jTextFieldNome;
    private javax.swing.JTextField jTextFieldTipo;
    private javax.swing.JButton jButtonExcluir;
    private static Evento Evento;
    private static int indice;
    // End of variables declaration
    static void CarregaContatosRelacionados(){
    	ContatosRelacionados.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {

                },
                new String [] {
                    "Nome", "Endereco", "Celular"
                }
            ) {
                boolean[] canEdit = new boolean [] {
                    false, false, false
                };

                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit [columnIndex];
                }
            });
    	DefaultTableModel modelo = (DefaultTableModel) ContatosRelacionados.getModel();
		for(int i=0;i<Evento.getContatos().size();i++){
			modelo.addRow(new String[]{Evento.getContatos().get(i).getNome(),Evento.getContatos().get(i).getEndereco(),Evento.getContatos().get(i).getDataDeAniversario()});
		}
    }
    static void CarregaAnotações(){
    	Anotações.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {

                },
                new String [] {
                    "Nome", "Data"
                }
            ) {
                boolean[] canEdit = new boolean [] {
                    false, false, false
                };

                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit [columnIndex];
                }
            });
    	DefaultTableModel modelo = (DefaultTableModel) Anotações.getModel();
		for(int i=0;i<Evento.getAnotacoes().size();i++){
			modelo.addRow(new String[]{Evento.getAnotacoes().get(i).getNome(),Evento.getAnotacoes().get(i).getData()});
		}
    }
}
